﻿@page "/Account/Manage/PersonalData"

@using Microsoft.AspNetCore.Identity
@using BlazorWebCSharp._1.Data

@inject UserManager<ApplicationUser> UserManager
@inject IdentityRedirectManager RedirectManager

<PageTitle>Personal Data</PageTitle>

<StatusMessage />
<h3>Personal Data</h3>

<FluentGrid>
    <FluentGridItem xs="12" sm="6">
        <p>Your account contains personal data that you have given us. This page allows you to download or delete that data.</p>
        <p>
            <strong>Deleting this data will permanently remove your account, and this cannot be recovered.</strong>
        </p>
        <form action="Account/Manage/DownloadPersonalData" method="post">
            <AntiforgeryToken />
            <FluentButton Type="ButtonType.Submit" Appearance="Appearance.Accent" Style="width:20%;">Download</FluentButton>
        </form>

        <hr />

        <p style="margin-top: 10px; text-align: end;">
            <FluentAnchor Href="Account/Manage/DeletePersonalData" Appearance="Appearance.Hypertext" >Delete your personal data</FluentAnchor>
        </p>
    </FluentGridItem>
</FluentGrid>

@code {
    [CascadingParameter]
    private HttpContext HttpContext { get; set; } = default!;

    protected override async Task OnInitializedAsync()
    {
        var user  = await UserManager.GetUserAsync(HttpContext.User);
        if (user is null)
        {
            RedirectManager.RedirectToInvalidUser(UserManager, HttpContext);
        }
    }
}
